﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;

namespace Turtle8
{
    public partial class DataPanel : UserControl
    { 
        enum SqlCommandType { INSERT, UPDATE }
        static private string[] cityArray;
        private SoldierCard sCard;

        #region Constructors
        public DataPanel(SoldierCard sCard)
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;

            this.sCard = sCard;
            initCityArray();
            comboBoxCity.Items.AddRange(cityArray);
        }
        #endregion

        #region private methods

        /// <summary>
        /// returns an array of Israeli cities.
        /// </summary>
        /// <returns></returns>
        static private void initCityArray()
        {
            SqlCommand selectCmd = SqlManager.SqlCommandFactory("SELECT city FROM IsraelCities");
            selectCmd.Connection.Open();

            SqlDataReader reader = selectCmd.ExecuteReader(); 
            List<string> list = new List<string>();

            while (reader.Read())
                list.Add(reader.GetString(0));

            cityArray = list.ToArray();

            selectCmd.Connection.Close();
            reader.Close();
        }
        private void PaintWithWhiteAllFields()
        {
            maskedTextBoxFirstName.BackColor = Color.White;
            maskedTextBoxLastName.BackColor = Color.White;
            maskedTextBoxArmyId.BackColor = Color.White;
            maskedTextBoxSocialId.BackColor = Color.White;
            maskedTextBoxHomePhone.BackColor = Color.White;
            maskedTextBoxCellPhone.BackColor = Color.White;
            maskedTextBoxEmail.BackColor = Color.White;
            comboBoxCity.BackColor = Color.White;
            maskedTextBoxStreet.BackColor = Color.White;
            maskedTextBoxBuildingNum.BackColor = Color.White;
            maskedTextBoxRelativeHomePhone.BackColor = Color.White;
            maskedTextBoxRelativeCellPhone.BackColor = Color.White;
            maskedTextBoxRelativeEmail.BackColor = Color.White;
        
        }

        private bool PaintWithYellow()
        {
            bool yellow = false;

            if (maskedTextBoxFirstName.Text == string.Empty)
            {
                maskedTextBoxFirstName.BackColor = Color.Yellow;
                yellow = true;
            }
            if (maskedTextBoxLastName.Text == string.Empty)
            {
                maskedTextBoxLastName.BackColor = Color.Yellow;
                yellow = true;
            }
            if ((maskedTextBoxArmyId.Text == string.Empty) ||
                (maskedTextBoxArmyId.errorProvider1.GetError(maskedTextBoxArmyId) != string.Empty))
            {
                maskedTextBoxArmyId.BackColor = Color.Yellow;
                yellow = true;
            }
            if ((maskedTextBoxSocialId.Text == string.Empty) ||
                (maskedTextBoxSocialId.errorProvider1.GetError(maskedTextBoxSocialId) != string.Empty))
            {
                maskedTextBoxSocialId.BackColor = Color.Yellow;
                yellow = true;
            }
            if (maskedTextBoxHomePhone.errorProvider1.GetError(maskedTextBoxHomePhone) != string.Empty)
            {
                maskedTextBoxHomePhone.BackColor = Color.Yellow;
                yellow = true;
            }
            if (maskedTextBoxCellPhone.errorProvider1.GetError(maskedTextBoxCellPhone) != string.Empty)
            {
                maskedTextBoxCellPhone.BackColor = Color.Yellow;
                yellow = true;
            }

            if (maskedTextBoxEmail.errorProvider1.GetError(maskedTextBoxEmail) != string.Empty)
            {
                maskedTextBoxEmail.BackColor = Color.Yellow;
                yellow = true;
            }

            if (maskedTextBoxRelativeHomePhone.errorProvider1.GetError(maskedTextBoxRelativeHomePhone) != string.Empty)
            {
                maskedTextBoxRelativeHomePhone.BackColor = Color.Yellow;
                yellow = true;
            }

            if (maskedTextBoxRelativeCellPhone.errorProvider1.GetError(maskedTextBoxRelativeCellPhone) != string.Empty)
            {
                maskedTextBoxRelativeCellPhone.BackColor = Color.Yellow;
                yellow = true;
            }

            if (maskedTextBoxRelativeEmail.errorProvider1.GetError(maskedTextBoxRelativeEmail) != string.Empty)
            {
                maskedTextBoxRelativeEmail.BackColor = Color.Yellow;
                yellow = true;
            }

            return yellow;

        }

        private bool modifyQualifiedTrack()
        {
            string insertStr = @"INSERT INTO [QualifiedTrack] (armyID)  VALUES (@armyID)";
            SqlCommand insertCmd = SqlManager.SqlCommandFactory(insertStr);
            insertCmd.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text;
            insertCmd.ExecuteNonQuery();

            return true;
        }


        //insert or updates [PersonalData] according to the parameter
        private bool modifyPersonalDataDB(SqlCommandType cmdType)
        {
            string sqlStr;
            if (cmdType == SqlCommandType.INSERT)
                sqlStr = CompanyManager.getSqlStringFromFile(@"\INSERT\PersonalData.INSERT.sql");
            else sqlStr = CompanyManager.getSqlStringFromFile(@"\UPDATE\PersonalData.UPDATE.sql");
            SqlCommand sqlCommand = SqlManager.SqlCommandFactory(sqlStr);

            //checks whether armyID is valid - it is the primary key
            sqlCommand.Parameters.Add("@firstName", SqlDbType.NVarChar).Value = maskedTextBoxFirstName.Text.Trim();
            sqlCommand.Parameters.Add("@lastName", SqlDbType.NVarChar).Value = maskedTextBoxLastName.Text.Trim();
            sqlCommand.Parameters.Add("@socialID", SqlDbType.NVarChar).Value = maskedTextBoxSocialId.Text.Trim();
            sqlCommand.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text.Trim();
            sqlCommand.Parameters.Add("@homePhone", SqlDbType.NVarChar).Value = maskedTextBoxHomePhone.Text.Trim();
            sqlCommand.Parameters.Add("@cellPhone", SqlDbType.NVarChar).Value = maskedTextBoxCellPhone.Text.Trim();
            sqlCommand.Parameters.Add("@email", SqlDbType.NVarChar).Value = maskedTextBoxEmail.Text.Trim();
            sqlCommand.Parameters.Add("@birthday", SqlDbType.Date).Value = dateTimePickerBirthDay.Value;
            sqlCommand.Parameters.Add("@city", SqlDbType.NVarChar).Value = comboBoxCity.Text.Trim();
            sqlCommand.Parameters.Add("@street", SqlDbType.NVarChar).Value = maskedTextBoxStreet.Text.Trim();

            if (!maskedTextBoxBuildingNum.Text.Equals(""))
                sqlCommand.Parameters.Add("@buildingNum", SqlDbType.SmallInt).Value = Int16.Parse(maskedTextBoxBuildingNum.Text.Trim());
            else sqlCommand.Parameters.Add("@buildingNum", SqlDbType.SmallInt).Value = System.DBNull.Value;

            if (!maskedTextBoxApartmentNum.Text.Equals(""))
                sqlCommand.Parameters.Add("@apartmentNum", SqlDbType.SmallInt).Value = Int16.Parse(maskedTextBoxApartmentNum.Text.Trim());
            else sqlCommand.Parameters.Add("@apartmentNum", SqlDbType.SmallInt).Value = System.DBNull.Value;

            if (pictureBox.Image != null)
                sqlCommand.Parameters.Add("@picture", SqlDbType.VarBinary).Value = CompanyManager.imageToByteArray(pictureBox.Image);
            else sqlCommand.Parameters.Add("@picture", SqlDbType.VarBinary).Value = System.DBNull.Value;

            sqlCommand.Parameters.Add("@comments", SqlDbType.NVarChar).Value = textBoxComments.Text.Trim();

            sqlCommand.ExecuteNonQuery();
            return true;

        }


        /// <summary>
        /// 
        /// </summary>
        private bool modifyFamilyDataDB(SqlCommandType cmdType)
        {
            string sqlStr;
            if (cmdType == SqlCommandType.INSERT)
                sqlStr = CompanyManager.getSqlStringFromFile(@"\INSERT\FamilyInfo.INSERT.sql");
            else sqlStr = CompanyManager.getSqlStringFromFile(@"\UPDATE\FamilyInfo.UPDATE.sql");

            SqlCommand sqlCommand = SqlManager.SqlCommandFactory(sqlStr);
            sqlCommand.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text.Trim();

            if (radioButtonIsMarriedYes.Checked)
                sqlCommand.Parameters.Add("@isMarried", SqlDbType.Bit).Value = true;
            else sqlCommand.Parameters.Add("@isMarried", SqlDbType.Bit).Value = false;

            sqlCommand.Parameters.Add("@wifeName", SqlDbType.NVarChar).Value = textBoxWifeName.Text.Trim();

            if (radioButtonIsChildrenYes.Checked)
                sqlCommand.Parameters.Add("@hasChildren", SqlDbType.Bit).Value = true;
            else sqlCommand.Parameters.Add("@hasChildren", SqlDbType.Bit).Value = false;

            sqlCommand.Parameters.Add("@childrenCtr", SqlDbType.TinyInt).Value = numericUpDownChildren.Value;
            sqlCommand.Parameters.Add("@childrenNames", SqlDbType.NVarChar).Value = textBoxChildrenNames.Text.Trim();

            try
            {
                sqlCommand.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// INSERT's or UPDATE's a soldiers data
        /// </summary>
        private bool modifyArmyInfoDB(SqlCommandType cmdType)
        {
            string sqlStr;
            if (cmdType == SqlCommandType.INSERT)
                sqlStr = CompanyManager.getSqlStringFromFile(@"\INSERT\ArmyInfo.INSERT.sql");
            else sqlStr = CompanyManager.getSqlStringFromFile(@"\UPDATE\ArmyInfo.UPDATE.sql");

            //creating the qualifications string
            String qualStr = String.Empty;
            //creating a word which is a concat of the qualifications. for example str="M4+M3+M203"
            foreach (string check in checkedListBoxQualifications.CheckedItems)
                qualStr += check + ",";
            //removing the last ',' if needed. (case no box is checked in checkedListBoxAuthorization)
            if (qualStr.Length != 0)
                qualStr = qualStr.Substring(0, qualStr.Length - 1);


            SqlCommand sqlCommand = SqlManager.SqlCommandFactory(sqlStr);
            sqlCommand.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text.Trim();
            sqlCommand.Parameters.Add("@position", SqlDbType.NVarChar).Value = comboBoxPosition.Text.Trim();
            sqlCommand.Parameters.Add("@qualifications", SqlDbType.NVarChar).Value = qualStr;
            sqlCommand.Parameters.Add("@dateArrival", SqlDbType.Date).Value = dateTimePickerArrival.Value;
            sqlCommand.Parameters.Add("@platoon", SqlDbType.TinyInt).Value = comboBoxPlatoon.Text.Trim();
            sqlCommand.Parameters.Add("@shoeSize", SqlDbType.TinyInt).Value = numericUpDownShoeSize.Value;
            sqlCommand.Parameters.Add("@shoeStatus", SqlDbType.NVarChar).Value = comboBoxShoeStatus.Text.Trim(); ;
            sqlCommand.Parameters.Add("@noShoeComment", SqlDbType.NVarChar).Value = comboBoxNoShoeReason.Text.Trim();
            sqlCommand.Parameters.Add("@idDiscStatus", SqlDbType.NVarChar).Value = comboBoxDiscStatus.Text.Trim();

            if (radioButtonIsActiveYes.Checked)
                sqlCommand.Parameters.Add("@isActive", SqlDbType.Bit).Value = true;
            else sqlCommand.Parameters.Add("@isActive", SqlDbType.Bit).Value = false;

            sqlCommand.ExecuteNonQuery();
            return true;
        }


        /// <summary>
        /// 
        /// </summary>
        private bool modifyContactInfoDB(SqlCommandType cmdType)
        {
            string sqlStr;
            if (cmdType == SqlCommandType.INSERT)
                sqlStr = CompanyManager.getSqlStringFromFile(@"\INSERT\ContactInfo.INSERT.sql");
            else sqlStr = CompanyManager.getSqlStringFromFile(@"\UPDATE\ContactInfo.UPDATE.sql");

            SqlCommand sqlCommand = SqlManager.SqlCommandFactory(sqlStr);
            sqlCommand.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text.Trim();
            sqlCommand.Parameters.Add("@firstName", SqlDbType.NVarChar).Value = maskedTextBoxRelativeFirstName.Text.Trim();
            sqlCommand.Parameters.Add("@lastName", SqlDbType.NVarChar).Value = maskedTextBoxRelativeLastName.Text.Trim();
            sqlCommand.Parameters.Add("@homePhone", SqlDbType.NVarChar).Value = maskedTextBoxRelativeHomePhone.Text.Trim();
            sqlCommand.Parameters.Add("@cellPhone", SqlDbType.NVarChar).Value = maskedTextBoxRelativeCellPhone.Text.Trim();
            sqlCommand.Parameters.Add("@email", SqlDbType.NVarChar).Value = maskedTextBoxRelativeEmail.Text.Trim();
            sqlCommand.Parameters.Add("@relation", SqlDbType.NVarChar).Value = comboBoxRelation.Text.Trim();
            sqlCommand.Parameters.Add("@adress", SqlDbType.NVarChar).Value = maskedTextBoxRelativeAdress.Text.Trim();

            try
            {
                sqlCommand.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        /// <summary>
        /// returns the value we receive from SqlDb casted.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="reader"></param>
        /// <param name="col_name"></param>
        /// <returns></returns>
        private DateTime castSqlValue(System.DateTime date, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return DateTime.Today;
            return (DateTime)reader[col_name];
        }
        private Boolean castSqlValue(System.Boolean b, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return false;
            return (Boolean)reader[col_name];
        }
        private Int16 castSqlValue(System.Int16 i, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return 0;
            return (Int16)reader[col_name];
        }
        private Byte castSqlValue(System.Byte b, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return 0;
            return (Byte)reader[col_name];
        }

        private Image castSqlValue(Image img, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return null;
            return CompanyManager.byteArrayToImage((byte[])reader[col_name]);
        }
        private String castSqlValue(String str, SqlDataReader reader, string col_name)
        {
            if (reader[col_name] == System.DBNull.Value)
                return String.Empty;
            return (String)reader[col_name];
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        public void Fill(SqlDataReader reader)
        {
            int ctr = reader.FieldCount;
            reader.Read();

            String str = string.Empty;
            Byte byte1 = 0;
            Boolean boolean = false;
            Int16 int16 = 0;
            Image img = null;
            DateTime date = DateTime.MinValue;


            //Data resolved from PersonalData database
            maskedTextBoxArmyId.Text = castSqlValue(str, reader, "armyID");
            maskedTextBoxSocialId.Text = castSqlValue(str, reader, "socialID");
            maskedTextBoxFirstName.Text = castSqlValue(str, reader, "firstName");
            maskedTextBoxLastName.Text = castSqlValue(str, reader, "lastName");
            maskedTextBoxHomePhone.Text = castSqlValue(str, reader, "homePhone");
            maskedTextBoxCellPhone.Text = castSqlValue(str, reader, "cellPhone");
            maskedTextBoxEmail.Text = castSqlValue(str, reader, "email");
            dateTimePickerBirthDay.Value = castSqlValue(date, reader, "birthday");
            comboBoxCity.Text = castSqlValue(str, reader, "city");
            maskedTextBoxStreet.Text = castSqlValue(str, reader, "street");
            maskedTextBoxBuildingNum.Text = Convert.ToString(castSqlValue(int16, reader, "buildingNum"));
            maskedTextBoxApartmentNum.Text = Convert.ToString(castSqlValue(int16, reader, "apartmentNum"));
            pictureBox.Image = castSqlValue(img, reader, "picture");
            textBoxComments.Text = castSqlValue(str, reader, "comments");

            //Data resolved from FamilyInfo database
            if ((bool)castSqlValue(boolean, reader, "isMArried"))
                radioButtonIsMarriedYes.Checked = true;
            else radioButtonIsMarriedNo.Checked = true;

            if ((bool)castSqlValue(boolean, reader, "hasChildren"))
                radioButtonIsChildrenYes.Checked = true;
            else radioButtonIsChildrenNo.Checked = true;

            numericUpDownChildren.Value = Convert.ToByte(castSqlValue(byte1, reader, "childrenCtr"));

            str = castSqlValue(str, reader, "childrenNames");
            if (str != null)
                str = str.Replace("+", ", ");
            textBoxChildrenNames.Text = str;


            //Data resolved from ArmyInfo database
            comboBoxPosition.Text = castSqlValue(str, reader, "position");

            string qual = castSqlValue(str, reader, "qualifications");
            string[] qualArr = qual.Split(',');
            CheckedListBox.ObjectCollection col = checkedListBoxQualifications.Items;
            try
            {
                foreach (string item in qualArr)
                    checkedListBoxQualifications.SetItemChecked(col.IndexOf(item), true);
            }
            catch (Exception)
            {
                //do nothing
            }

            comboBoxPlatoon.Text = Convert.ToString(castSqlValue(byte1, reader, "platoon"));
            numericUpDownShoeSize.Text = Convert.ToString(castSqlValue(byte1, reader, "shoeSize"));
            comboBoxNoShoeReason.Text = castSqlValue(str, reader, "noShoeComment");
            comboBoxDiscStatus.Text = castSqlValue(str, reader, "idDiscStatus");
            dateTimePickerArrival.Value = castSqlValue(date, reader, "dateArrival");

            if ((bool)castSqlValue(boolean, reader, "isActive"))
                radioButtonIsActiveYes.Checked = true;
            else radioButtonIsActiveNo.Checked = true;

            //Data resolved from RelativeInfo database
            maskedTextBoxRelativeFirstName.Text = Convert.ToString(castSqlValue(str, reader, "relativeFirstName"));
            maskedTextBoxRelativeLastName.Text = Convert.ToString(castSqlValue(str, reader, "relativeLastName"));
            maskedTextBoxRelativeHomePhone.Text = Convert.ToString(castSqlValue(str, reader, "relativeHomePhone"));
            maskedTextBoxRelativeCellPhone.Text = Convert.ToString(castSqlValue(str, reader, "relativeCellPhone"));
            maskedTextBoxRelativeEmail.Text = Convert.ToString(castSqlValue(str, reader, "relativeMail"));
            comboBoxRelation.Text = Convert.ToString(castSqlValue(str, reader, "relativeRelation"));
            maskedTextBoxRelativeAdress.Text = Convert.ToString(castSqlValue(str, reader, "relativeMail"));

            reader.Close();
        }

       

        #region event_handlers
        private void radioButtonIsMarriedYes_CheckedChanged(object sender, EventArgs e)
        {
            textBoxWifeName.Enabled = true;
        }

        private void radioButtonIsMarriedNo_CheckedChanged(object sender, EventArgs e)
        {
            textBoxWifeName.Enabled = false;
            textBoxWifeName.Clear();
        }

        private void radioButtonIsChildrenYes_CheckedChanged(object sender, EventArgs e)
        {
            numericUpDownChildren.Enabled = true;
            textBoxChildrenNames.Enabled = true;
        }

        private void radioButtonIsChildrenNo_CheckedChanged(object sender, EventArgs e)
        {
            numericUpDownChildren.Enabled = false;
            textBoxChildrenNames.Enabled = false;
            numericUpDownChildren.Value = 0;
        }

        private void comboBoxShoeStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBoxNoShoeReason.Text = String.Empty;
            if (comboBoxShoeStatus.Text.Equals("אין"))
                comboBoxNoShoeReason.Enabled = true;
            else comboBoxNoShoeReason.Enabled = false;
        }
        private void buttonClearFields_Click(object sender, EventArgs e)
        {
            DialogResult result;
            if (sender.Equals(this))
            {
                sCard.changeMainPanel(SoldierCard.PanelState.NewSoldierDataCard, string.Empty);
            }
            else
            {
                result = MessageBox.Show("?האם אתה בטוח שברצונך לאפס את השדות", "!שים לב", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    sCard.changeMainPanel(SoldierCard.PanelState.NewSoldierDataCard, string.Empty);
                }
            }
        }

        
        private void pictureBox_Click(object sender, EventArgs e)
        {
            if (pictureBox.Image !=null)
                new PictureBoxForm(pictureBox.Image, maskedTextBoxFirstName.Text, maskedTextBoxLastName.Text).ShowDialog();
        }

        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (pictureBox.Image != null)
            {
                toolTip.Active = true;
                toolTip.SetToolTip(pictureBox, "לחץ על התמונה להגדלה");
            }
            else toolTip.Active = false;
        }

        private void buttonGo_Click(object sender, EventArgs e)
        {
            PaintWithWhiteAllFields();
            bool isInsertOK = true;

            //checks that all of the * fields are fill and that there is no error provider
            if (!PaintWithYellow())
            {
                string selectStr = @"SELECT COUNT(armyId) FROM PersonalData WHERE armyId=@armyID";
                SqlCommand selectCmd = SqlManager.SqlCommandFactory(selectStr);
                selectCmd.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = maskedTextBoxArmyId.Text;
                int armyIdExists = Convert.ToInt32(selectCmd.ExecuteScalar());

                //there isn't a soldier with this armyID in database --->>> add this new soldier to 4 databases:
                //[PersonalData], [ArmyInfo], [FamilyData], [ContactInfo]
                if (armyIdExists == 0)
                {
                    isInsertOK =
                               modifyPersonalDataDB(SqlCommandType.INSERT)
                               && modifyFamilyDataDB(SqlCommandType.INSERT)
                               && modifyArmyInfoDB(SqlCommandType.INSERT)
                               && modifyContactInfoDB(SqlCommandType.INSERT)
                               && modifyQualifiedTrack();

                    if (!isInsertOK)
                    {
                        MessageBox.Show(".אירעה תקלה. פרטי הלוחם לא נוספו למסד הנתונים");
                        return;
                    }

                    else
                    {
                        buttonClearFields_Click(this, e);
                        MessageBox.Show("הכרטיס התווסף למאגר הנתונים בהצלחה", "עידכון",
                                         MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        sCard.refresh();
                        return;
                    }
                }
                //there is already a soldier with this armyID --->>> ask the user if he really want to update the data.
                else
                {
                    DialogResult result;
                    result = MessageBox.Show("?לוחם בעל מספר אישי זה קיים במערכת. האם ברצונך לעדכן פרטיו", "!שים לב", MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        bool b = modifyPersonalDataDB(SqlCommandType.UPDATE)
                               && modifyFamilyDataDB(SqlCommandType.UPDATE)
                               && modifyArmyInfoDB(SqlCommandType.UPDATE)
                               && modifyContactInfoDB(SqlCommandType.UPDATE);
                        sCard.refresh();
                    }
                }
            }
            else
            {
                MessageBox.Show("בדוק את השדות המודגשים", "שגיאות בפרטים",
                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            sCard.changeMainPanel(SoldierCard.PanelState.Default, string.Empty);
        }

        private void buttonPicChoose_Click(object sender, EventArgs e)
        {
            OpenImageFileDialog dlg = new OpenImageFileDialog();
            DialogResult dlg_result;
            if ((dlg_result = dlg.ShowDialog()) == DialogResult.OK)
                pictureBox.ImageLocation = dlg.FileName;
        }

        private void textBoxEmail_Enter(object sender, EventArgs e)
        {
            changeLanguage("en");
        }

        private void textBoxEmail_Leave(object sender, EventArgs e)
        {
            changeLanguage("he");
        }
        private void checkedListBoxQualifications_Enter(object sender, EventArgs e)
        {
            CheckedListBox ctrl = (CheckedListBox)sender;
            ctrl.Size = new Size(ctrl.Size.Width, 19 + 6 * 15);
        }

        private void checkedListBoxQualifications_Leave(object sender, EventArgs e)
        {
            Control ctrl = (Control)sender;
            ctrl.Size = new Size(ctrl.Size.Width, 19 + 15);
        }
        #endregion


        private void changeLanguage(string lang)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new System.Globalization.CultureInfo(lang));
        }

        

      


    }



}
